public class StringBuilderDemo3 {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        printArray(arr);
    }
    public static void printArray(int[] arr) {
        if(arr == null){
            System.out.println("数组为null");
            return;
        }
        if(arr.length == 0){
            System.out.println("数组长度为0");
            return;
        }
        //创建StringBuilder对象
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < arr.length; i++) {
            sb.append(arr[i]);
            if (i < arr.length - 1) {
                sb.append(", ");
            }else {
                sb.append("]");
            }
        }
        //输出结果
        System.out.println(sb);
    }
}
